package com.springcloud.zuul.exception;

import com.springcloud.zuul.common.constant.ServiceCode;
import com.springcloud.zuul.common.constant.ServiceErrCode;

/**
 * @program: springcloud-zuul
 * @description: 自定义异常拦截
 * @author: zhlu
 * @create: 2019-12-26 10:21
 * @Introduction(说明背景故事)
 **/
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private String errorCode= "500";

    private String errorMessage;

    public ServiceException(String errorMessage) {
        super(errorMessage);
        this.errorMessage = errorMessage;
    }

    public ServiceException(String errorMessage, Throwable e) {
        super(errorMessage, e);
        this.errorMessage = errorMessage;
    }

    public ServiceException(String errorCode, String errorMessage) {
        super(errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public ServiceException(String errorCode, String errorMessage, Throwable e) {
        super(errorMessage, e);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public ServiceException(ServiceCode serviceCode) {
        super(serviceCode.getMsg());
        this.errorCode = serviceCode.getCode();
        this.errorMessage = serviceCode.getMsg();
    }

    public ServiceException(ServiceCode serviceCode, Throwable e) {
        super(serviceCode.getMsg(), e);
        this.errorCode = serviceCode.getCode();
        this.errorMessage = serviceCode.getMsg();
    }

    public ServiceException(ServiceErrCode serviceErrCode) {
        super(serviceErrCode.getMsg());
        this.errorCode = serviceErrCode.getCode();
    }

    public ServiceException(ServiceErrCode serviceErrCode, Throwable e) {
        super(serviceErrCode.getMsg(), e);
        this.errorCode = serviceErrCode.getCode();
        this.errorMessage = serviceErrCode.getMsg();
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
}
